//
//  AppDelegate.m
//  yunyan
//
//  Created by haichuang on 2018/2/11.
//  Copyright © 2018年 haichuang. All rights reserved.
//



#import "AppDelegate.h"
#import "MainTabBarController.h"
#import "LoginViewController.h"
#import "LeadVC.h"
@interface AppDelegate ()
@property (nonatomic, strong) MainTabBarController * mian;
@property (strong, nonatomic) LeadVC *leadVC;
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    // _mian = [[MainTabBarController alloc]init];
    [UIApplication sharedApplication].statusBarHidden = NO;
 
    [self crearShareSDK];
    //引导页
    //判断是否加载引导页
    NSString *lastEdition=[[NSUserDefaults standardUserDefaults] objectForKey:@"edition"];

    NSDictionary *dic=[[NSBundle mainBundle]infoDictionary];
    NSString *str=dic[@"CFBundleShortVersionString"];

    //如果有新版就加载引导页
    if ([lastEdition isEqualToString:str]) {


//        LoginViewController * login = [[LoginViewController alloc]init];
//        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:login];
        
        MainTabBarController * root = [[MainTabBarController alloc]init];
//        [UIApplication sharedApplication].keyWindow.rootViewController = root;

        self.window.rootViewController = root;
    }else{
    
        _leadVC = [[LeadVC alloc]init];
//        UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:_leadVC];

        self.window.rootViewController = _leadVC;
   }
//
    
    [[NSUserDefaults standardUserDefaults] setValue:str forKey:@"edition"];
    [[NSUserDefaults standardUserDefaults] synchronize];
    
    [self getBannerDataRequest];
    [self getCategoryDataRequest];
    
    NSLog(@"ududid=%@",[SHJudgeTools getDeviceId]);
    
    // self.window.rootViewController = _mian;
    
    [self.window makeKeyAndVisible];
    
    //键盘第三方
    //关闭设置为NO, 默认值为NO.
    [IQKeyboardManager sharedManager].enable = YES;
    //如果产品需要当键盘弹起时，点击背景收起键盘，也是一行代码解决。
    [IQKeyboardManager sharedManager].shouldResignOnTouchOutside = YES;
    
    
    
    
    return YES;
}

-(void)crearShareSDK{
    
    [ShareSDK registerActivePlatforms:@[
                                        @(SSDKPlatformTypeSinaWeibo),
                                        @(SSDKPlatformTypeMail),
                                        @(SSDKPlatformTypeSMS),
                                        @(SSDKPlatformTypeCopy),
                                        @(SSDKPlatformTypeWechat),
                                        @(SSDKPlatformTypeQQ),
                                        @(SSDKPlatformTypeRenren),
                                        @(SSDKPlatformTypeFacebook),
                                        @(SSDKPlatformTypeTwitter),
                                        @(SSDKPlatformTypeGooglePlus)
                                        ]
                             onImport:^(SSDKPlatformType platformType)
     {
         switch (platformType)
         {
             case SSDKPlatformTypeWechat:
                 [ShareSDKConnector connectWeChat:[WXApi class]];
                 break;
             case SSDKPlatformTypeQQ:
                 [ShareSDKConnector connectQQ:[QQApiInterface class] tencentOAuthClass:[TencentOAuth class]];
                 break;
             case SSDKPlatformTypeSinaWeibo:
                 [ShareSDKConnector connectWeibo:[WeiboSDK class]];
                 break;
             default:
                 break;
         }
     }
                      onConfiguration:^(SSDKPlatformType platformType, NSMutableDictionary *appInfo)
     {
         
         switch (platformType)
         {
             case SSDKPlatformTypeSinaWeibo:
                 //设置新浪微博应用信息,其中authType设置为使用SSO＋Web形式授权
                 [appInfo SSDKSetupSinaWeiboByAppKey:@"2048324093"
                                           appSecret:@"fe52d8a0d3f9ebc0cdeb6f96f1190064"
                                         redirectUri:@"http://www.haichuang.pro"
                                            authType:SSDKAuthTypeBoth];
                 break;
             case SSDKPlatformTypeWechat:
                 [appInfo SSDKSetupWeChatByAppId:@"wx583a0f6ee26dcded"
                                       appSecret:@"a8f826084e44f9f901c74fe055e5f9a1"];
                 break;
             case SSDKPlatformTypeQQ:
                 [appInfo SSDKSetupQQByAppId:@"1106828634"
                                      appKey:@"HyEhzVRsuKBYkPhb"
                                    authType:SSDKAuthTypeBoth];
                 break;
             default:
                 break;
         }
     }];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

-(void)getCategoryDataRequest{
    
    
    [PostNetWorking netWorkingStr:RequestUrlStr(main_class_api)  Success:^(id responseObject) {
        
        if ([responseObject isKindOfClass:[NSArray class]]) {
            NSArray * array = responseObject;
            
            
            NSMutableArray * className = @[].mutableCopy;
            if (className) {
                [className removeAllObjects];
            }
            NSMutableArray * classimage = @[].mutableCopy;
            if (classimage) {
                [classimage removeAllObjects];
            }
            for (NSDictionary * dic in array) {
                [className addObject:dic[@"class_name"]];
                [classimage addObject:dic[@"class_pic"]];
            }
            USER_DEFAULTSet(className, @"className");
            USER_DEFAULTSet(classimage, @"classimage");
     
        }else{
            
        }
        NSLog(@"responseObject = %@",responseObject);
        
    } failed:^(NSURLSessionDataTask * _Nullable task,NSError *error) {
        
  
    }];
    
}

-(void)getBannerDataRequest{
    
    
    [PostNetWorking netWorkingStr:RequestUrlStr(get_banner_api)  Success:^(id responseObject) {
        
        if ([responseObject isKindOfClass:[NSArray class]]) {
            NSArray * array = responseObject;
        
            
            USER_DEFAULTSet(array , @"bannerArr");
         
        }else{
            
        
        }
        NSLog(@"responseObject = %@",responseObject);
        
    } failed:^(NSURLSessionDataTask * _Nullable task,NSError *error) {
        
    }];
    
}




@end
